<html>
	<head>
		<title>index.html</title>
		<script src="http://yui.yahooapis.com/3.1.1/build/yui/yui-min.js"></script>


		<!--CSS file (default YUI Sam Skin) -->
		<link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/2.8.1/build/datatable/assets/skins/sam/datatable.css">

		<!-- Dependencies -->
		<script src="http://yui.yahooapis.com/2.8.1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
		<script src="http://yui.yahooapis.com/2.8.1/build/element/element-min.js"></script>
		<script src="http://yui.yahooapis.com/2.8.1/build/datasource/datasource-min.js"></script>

		<!-- OPTIONAL: JSON Utility (for DataSource) -->
		<script src="http://yui.yahooapis.com/2.8.1/build/json/json-min.js"></script>

		<!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
		<script src="http://yui.yahooapis.com/2.8.1/build/connection/connection-min.js"></script>

		<!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
		<script src="http://yui.yahooapis.com/2.8.1/build/get/get-min.js"></script>

		<!-- Source files -->
		<script src="http://yui.yahooapis.com/2.8.1/build/datatable/datatable-min.js"></script>
	</head>
	<body class="yui-skin-sam">
		<h1>ShootPike</h1>
		<div id="table"></div>
		<script>
			YUI().use("io-base", "json", function (Y) {
				function drawTable(id, o, args) {
					var result = [];
					var task = {};

					var data = Y.JSON.parse(o.responseText);
					for (var i = 0; i < data.res.length; i++ ) {
						var test = data.res[i];
						for (var j = 0; j < test.rows.length; j++) {
							var row = test.rows[j];
							if (!task[row[0]]) {
								task[row[0]] = {};
								task[row[0]].test = row[0];
							}
							task[row[0]][test.id] = row[2];
						}
					}
					
					var columns = [];
					var fields = [];
					columns.push({ key: "test", label: "test" });
					fields.push({key: "test"});
					for (var i = 0; i < data.ids.length; i++) {
						columns.push({ key: data.ids[i],
									   label: data.ids[i] });
						fields.push({key: data.ids[i]});
					}
					for (var t in task) {
						result.push(task[t]);
					}

					var dataSource = 
						new YAHOO.util.LocalDataSource(result);
					//dataSource.responseType = YAHOO.util.LocalDataSource.TYPE_JSON;
					dataSource.responseSchema = {
						fields: fields
					};
					var dataTable = 
						new YAHOO.widget.DataTable("table", columns, dataSource);
				}


				Y.io("/shootpike/getdata", { 
					on: {
						success: drawTable
					}
				});
			});
		</script>
	</body>
</html>
